package edu.westga.vocalengineer.audio.gui;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * JTransformSliderPanel
 *  A custom panel to display a JSlider with a label
 *  and a JTextField that tracks the value of the slider.
 * @author mfarmer2
 *
 */
public class JTransformSliderPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	private JLabel sliderLabel;
	private JSlider theSlider;
	private JTextField outputText;
	
	/**
	 * Sets up an instance of JTransformSliderPanel.  Fire-and-forget.
	 * @param label The text label for the slider.
	 * @param min The minimum value for the slider.
	 * @param max The maximum value for the slider.
	 * @param current The initial value of the slider.
	 */
	public JTransformSliderPanel(String label, int min, int max, int current) {
		super();
		sliderLabel = new JLabel(label);
		theSlider = new JSlider(min, max, current);
		outputText = new JTextField(5);
		outputText.setText(""+theSlider.getValue());
		theSlider.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				 JSlider source = (JSlider)e.getSource();  // get the slider
				 outputText.setText(""+source.getValue());
			}
		});
		outputText.setEditable(false);
		this.add(sliderLabel);
		this.add(outputText);
		this.add(theSlider);		
	}
	
	/**
	 * Gets the current slider value.
	 * @return The value of the slider.
	 */
	public int getValue() {
		return theSlider.getValue();
	}
	
}
